Fix #11481: Count signature names as consistent if one of them is a wildcard #12033
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the
i11481a.scala
test ("Bad" example) is modified to the following ("Good" example), it works:In the Bad case, at some point, the typer tries to check if the following subtyping holds:
It fails in the Bad case. In the Good case, it checks for:
And succeeds.
The reason for failure can be traced to here:
https://github.com/lampepfl/dotty/blob/a0707985bfdb40a29e79b1f034e6caa0570374f8/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L684
Typer checks the signatures of the involved methods. The following is the debug of the variables involved in that line:
Note
004
line for each output, the signatures for Bad and Good cases vary: it is Object for Good case but wildcard for bad case.It seems this is because for the Good case, the wildcard in question has bounds which is not the case for the Bad case:
It seems having bounds makes the signatures assume the form of those bounds whereas not having bounds means leaving a wildcard as a wildcard:
https://github.com/lampepfl/dotty/blob/a0707985bfdb40a29e79b1f034e6caa0570374f8/compiler/src/dotty/tools/dotc/core/TypeErasure.scala#L824-L827
In this PR I chose to simply treat the signatures as consistent if the names being compared involve a wildcard. I am not sure if this is the right fix or a more elaborate fix involving bounds should be devised.